<?php
/**
* @file $Id: Menu.php 526 2007-05-21 18:24:48Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if (!count($_FOCUS['Menu'])) {
	$menu = array();
	$FocusModules = array(	'School_Setup'       => true
						  , 'Students'           => true
						  , 'Users'              => true
						  , 'Scheduling'         => true
						  , 'Grades'             => true
						  , 'Attendance'         => true
						  , 'Eligibility'        => true
						  , 'Discipline'         => true
						  , 'School_Information' => true
						  , 'My_Child'           => true
						  , 'My_Information'     => true
						  , 'Billing'            => true
						  , 'Reports'            => true
						 );

	foreach ($FocusModules as $module => $include) {
		$menu[$module] = array();
	}

	foreach ($FocusModules as $module => $include) {
		if ($module != 'My_Child' 
		&& $module != 'My_Information' 
		&& $module!='School_Information'
		){
			include($staticpath."modules/$module/Menu.php");
		}
	}
	
	$handle = opendir($staticpath."modules/");
	if ($handle) {
		if (!is_array($IgnoreFiles)) {
			$IgnoreFiles=Array();
		}
		
		while (false !== ($folder = readdir($handle))) {
			if($folder != "." 
			&& $folder != ".." 
			&& !in_array($folder, $IgnoreFiles)
			){
				include($staticpath."modules/$folder/Menu.php");
			}
		}
	}
	
	// to make the reports menu the last one
	if ($menu['Reports']) {
		$menu_reports = $menu['Reports'];
		unset($menu['Reports']);
		$menu['Reports'] = $menu_reports;
	}

	$profile = User('PROFILE');
	$user_profile_id = User('PROFILE_ID');
	$user_username = User('USERNAME');
	if (is_numeric($user_profile_id)) {
		$can_use_RET = DBGet(DBQuery("
				SELECT        MODNAME 
				FROM          PROFILE_EXCEPTIONS 
				WHERE         PROFILE_ID = '$user_profile_id' 
				 AND          CAN_USE = 'N'
				"), array(), array('MODNAME'));
	}
	else {
		$can_use_RET = DBGet(DBQuery("
				SELECT        MODNAME 
				FROM          USER_EXCEPTIONS 
				WHERE         USERNAME = '$user_username' 
				 AND          CAN_USE = 'N'
				"), array(), array('MODNAME'));
	}
	unset($user_username);
	unset($user_profile_id);
	
	foreach ($menu as $modcat => $profiles) {
		if ($profiles[$profile]) {
			$_FOCUS['Menu'][$modcat] = $profiles[$profile];
		}
		
		if (User('PROFILE') == 'admin' 
		|| true  //seems to me that this always runs... 
		){
			if (count($can_use_RET)) {
				foreach ($_FOCUS['Menu'] as $modcat => $programs) {
					foreach ($programs as $program => $title) {
						if ($can_use_RET[$program] 
						&& !($_REQUEST['modname'] == 'Users/Permissions.php' 
						 && !$can_use_RET['Users/Permissions.php'] ) 
						&& !($_REQUEST['modname'] == 'Users/Profiles.php' 
						 && !$can_use_RET['Users/Profiles.php'] )
						){
							unset($_FOCUS['Menu'][$modcat][$program]);
						}
					}
				}
			}
			
			if (count($exceptions[$modcat])) {
				foreach ($exceptions[$modcat] as $program => $true) {
					if (!AllowEdit($program) 
					&& $_REQUEST['modname'] != 'Users/Permissions.php' 
					&& $_REQUEST['modname'] != 'Users/Profiles.php'
					){
						unset($_FOCUS['Menu'][$modcat][$program]);
					}
				}
			}
		}
	}

	if (User('PROFILE') == 'student') {
		unset($_FOCUS['Menu']['Users']);
	}
}
?>